<template>
	<view class="content">
		<view class="gradient-bg">
			<view class="flex-row-between" style="margin-bottom: 8rpx;">
				<view class="flex-row">
					<text class="white-text font-24">单据编号</text>
					<text class="white-text font-24" style="margin-left: 20rpx;">{{taskInfo.no}}</text>
				</view>
			</view>
			<!-- 渐变背景 -->
			<!-- <view scroll-y style="height: calc(100vh - 377rpx);"> -->
			<view scroll-x class="table-wrap tb-auto-height">
				<zb-table :show-header="true" :columns="detailColumn"  :border="true" :data="detailData">
				</zb-table>
			</view>
			<!-- </view> -->
			<view @click="dispatch" v-if="!pageType" class="botton p-botton font-30"
				style="height: 92rpx; line-height:92rpx;margin: 50rpx 25rpx;">
				出库
			</view>
		</view>
	</view>
</template>

<script>
	import {
		validNum
	} from "@/utils/common"
	import {
		getTaskInfoById,
		getAdjustOutBillDetailList,
		executeAdjustOutBill
	} from "./api"


	export default {
		onLoad(option) {
			this.taskId = option.id;
			this.pageType = option.type
		},
		created() {
			this.tableHeiht = this.windowHeight - 420;
			this.getTaskDetail();
		},
		data() {
			return {
				pageType:'',
				tableHeiht: 0,
				taskId: '',
				taskInfo: {},
				code: '',
				number: 12,
				detailData: [],
				detailColumn: [
					{ type:'index', label: '序号', align: 'center', width:54 },
					{
						name: 'productNo',
						label: '物料编号',
						fixed: false,
						emptyString: '--',						
						width:100
					},
					{
						name: 'productName',
						label: '物料',
						fixed: true,
						sorter: false,
						width:100
					},
					{
						name: 'qty',
						label: '数量',
						width:60
					},
					{
						name: 'productUnit',
						label: '单位',
					},
					// {
					// 	name: 'batchNo',
					// 	label: '批次号'
					// },
				]

			}
		},
		computed: {

		},
		methods: {
			getTaskDetail() {
				getTaskInfoById(this.taskId).then(res => {
					if (res.code == 200) {
						this.taskInfo = res.data
						// 继续查询收货任务明细
						getAdjustOutBillDetailList({
							billNo: this.taskInfo.no,
						}).then(res => {
							if (res.code == 200) {
								this.detailData = res.rows;
							}else {
									res.msg && this.$modal.confirmClose(res.msg)
							}
						})
					}
				})
			},
			// 分配
			dispatch() {
				this.$modal.confirm('确定出库？').then(() => {
					let obj = [{
						no: this.taskInfo.no
					}]
					this.$modal.loading("加载中...")
					executeAdjustOutBill(obj).then(res => {
						this.$modal.closeLoading()
						if (res.code == 200) {
							this.$modal.confirmClose("出库成功，返回页面","返回").then( res=>{
								uni.navigateBack();
							})
							// this.$modal.msgSuccess("操作成功");
							// this.getTaskDetail();
							// 延迟1秒跳转
							// uni.$emit('refreshList', {
							// 	msg: '页面更新'
							// })
							// setTimeout(() => {
							// 	uni.navigateBack();
							// }, 1000);
						}else {
							res.msg && this.$modal.confirmClose(res.msg)
						}
					})
				})
			}
		}
	}
</script>

<style>
	page {
		background-color: #F8F8F8;
	}
</style>
<style scoped>

</style>